package br.com.view;

import br.com.dao.ConectaBanco;
import br.com.dao.ModeloTabela;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Cícero
 */
public class Frm_CadFabricante extends javax.swing.JFrame {

    ConectaBanco conexao = new ConectaBanco();
    
    /**
     * Creates new form Frm_CadFabricante
     */
    public Frm_CadFabricante() {
        initComponents();
        conexao.conexao();
        geraTabela("select * from cadastrofabricante order by idfabricante");
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("bancosysepi?zeroDateTimeBehavior=convertToNullPU").createEntityManager();
        acessarsistemaQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a FROM Acessarsistema a");
        acessarsistemaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : acessarsistemaQuery.getResultList();
        cadastrofabricanteQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT c FROM Cadastrofabricante c");
        cadastrofabricanteList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : cadastrofabricanteQuery.getResultList();
        lblCadastroFornecedor = new javax.swing.JLabel();
        lblIdFabricante = new javax.swing.JLabel();
        textIdFabricante = new javax.swing.JTextField();
        lblCnpj = new javax.swing.JLabel();
        lblCpf = new javax.swing.JLabel();
        lblNome = new javax.swing.JLabel();
        textNome = new javax.swing.JTextField();
        lblBairro = new javax.swing.JLabel();
        lblCep = new javax.swing.JLabel();
        lblTelefone = new javax.swing.JLabel();
        textBairro = new javax.swing.JTextField();
        lblTelComercial = new javax.swing.JLabel();
        lblCelular = new javax.swing.JLabel();
        lblEmail1 = new javax.swing.JLabel();
        textEmail1 = new javax.swing.JTextField();
        lblEmail2 = new javax.swing.JLabel();
        textEmail2 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textAreaObs = new javax.swing.JTextArea();
        lblEndereco = new javax.swing.JLabel();
        textEndereco = new javax.swing.JTextField();
        lblCidade = new javax.swing.JLabel();
        textCidade = new javax.swing.JTextField();
        lblUf = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableFabricante = new javax.swing.JTable();
        boxUF = new javax.swing.JComboBox();
        formattedTextCPF = new javax.swing.JFormattedTextField();
        FormattedTextCNPJ = new javax.swing.JFormattedTextField();
        btnNovo = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnSalvar = new javax.swing.JButton();
        formattedTextCep = new javax.swing.JFormattedTextField();
        formattedTextCom = new javax.swing.JFormattedTextField();
        formattedTextCel = new javax.swing.JFormattedTextField();
        formattedTextTel = new javax.swing.JFormattedTextField();
        btnProximo = new javax.swing.JButton();
        btnPrimeiro = new javax.swing.JButton();
        btnAnterior = new javax.swing.JButton();
        btnUltimo = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SysEpi - Cadastro Fornecedor");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblCadastroFornecedor.setFont(new java.awt.Font("Tahoma", 1, 22)); // NOI18N
        lblCadastroFornecedor.setText("Cadastro Fornecedor");
        getContentPane().add(lblCadastroFornecedor, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 20, -1, -1));

        lblIdFabricante.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblIdFabricante.setText("Codigo:");
        getContentPane().add(lblIdFabricante, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, -1, -1));

        textIdFabricante.setEnabled(false);
        getContentPane().add(textIdFabricante, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 50, 60, -1));

        lblCnpj.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCnpj.setText("CNPJ:");
        getContentPane().add(lblCnpj, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 100, -1, -1));

        lblCpf.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCpf.setText("CPF:");
        getContentPane().add(lblCpf, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 100, -1, -1));

        lblNome.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblNome.setText("Nome:");
        getContentPane().add(lblNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 130, -1, -1));

        textNome.setEnabled(false);
        getContentPane().add(textNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 130, 400, -1));

        lblBairro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblBairro.setText("Bairro:");
        getContentPane().add(lblBairro, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 240, -1, -1));

        lblCep.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCep.setText("Cep:");
        getContentPane().add(lblCep, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 270, -1, -1));

        lblTelefone.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblTelefone.setText("Telefone:");
        getContentPane().add(lblTelefone, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 360, -1, -1));

        textBairro.setEnabled(false);
        getContentPane().add(textBairro, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 240, 200, -1));

        lblTelComercial.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblTelComercial.setText("Tel. Comercial:");
        getContentPane().add(lblTelComercial, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 330, -1, -1));

        lblCelular.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCelular.setText("Celular:");
        getContentPane().add(lblCelular, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 390, -1, -1));

        lblEmail1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblEmail1.setText("E-mail 1:");
        getContentPane().add(lblEmail1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 420, -1, -1));

        textEmail1.setEnabled(false);
        getContentPane().add(textEmail1, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 420, 390, -1));

        lblEmail2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblEmail2.setText("E-mail 2:");
        getContentPane().add(lblEmail2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 450, -1, -1));

        textEmail2.setEnabled(false);
        textEmail2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textEmail2ActionPerformed(evt);
            }
        });
        getContentPane().add(textEmail2, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 450, 390, -1));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Observações:");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 480, -1, -1));

        textAreaObs.setColumns(20);
        textAreaObs.setRows(5);
        textAreaObs.setEnabled(false);
        jScrollPane1.setViewportView(textAreaObs);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 480, 360, 50));

        lblEndereco.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblEndereco.setText("Endereço:");
        getContentPane().add(lblEndereco, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 180, -1, -1));

        textEndereco.setEnabled(false);
        getContentPane().add(textEndereco, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 180, 310, -1));

        lblCidade.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCidade.setText("Cidade:");
        getContentPane().add(lblCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 210, -1, -1));

        textCidade.setEnabled(false);
        getContentPane().add(textCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 210, 277, -1));

        lblUf.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblUf.setText("UF:");
        getContentPane().add(lblUf, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 210, -1, -1));

        tableFabricante.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jScrollPane2.setViewportView(tableFabricante);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 80, 500, 460));

        boxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MG", "MS", "MT", "PA", "PB", "PE", "PI", "PR", "RJ", "RN", "RO", "RR", "RS", "SC", "SE", "SP", "TO" }));
        boxUF.setEnabled(false);
        getContentPane().add(boxUF, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 210, 50, -1));

        try {
            formattedTextCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        formattedTextCPF.setEnabled(false);
        getContentPane().add(formattedTextCPF, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 100, 130, -1));

        try {
            FormattedTextCNPJ.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        FormattedTextCNPJ.setEnabled(false);
        getContentPane().add(FormattedTextCNPJ, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, 142, -1));

        btnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon(42).png"))); // NOI18N
        btnNovo.setText("Novo");
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });
        getContentPane().add(btnNovo, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 560, -1, -1));

        btnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (7).png"))); // NOI18N
        btnAlterar.setText("Alterar");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAlterar, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 560, -1, -1));

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (4).png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(btnCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 560, -1, -1));

        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (3).png"))); // NOI18N
        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });
        getContentPane().add(btnExcluir, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 560, -1, -1));

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (29).png"))); // NOI18N
        btnSalvar.setText("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });
        getContentPane().add(btnSalvar, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 560, -1, -1));

        try {
            formattedTextCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        formattedTextCep.setEnabled(false);
        getContentPane().add(formattedTextCep, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 270, 100, -1));

        try {
            formattedTextCom.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        formattedTextCom.setEnabled(false);
        getContentPane().add(formattedTextCom, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 330, 110, -1));

        try {
            formattedTextCel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        formattedTextCel.setEnabled(false);
        getContentPane().add(formattedTextCel, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 390, 109, -1));

        try {
            formattedTextTel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        formattedTextTel.setEnabled(false);
        getContentPane().add(formattedTextTel, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 360, 117, -1));

        btnProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (24).png"))); // NOI18N
        btnProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProximoActionPerformed(evt);
            }
        });
        getContentPane().add(btnProximo, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 560, -1, -1));

        btnPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (43).png"))); // NOI18N
        btnPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrimeiroActionPerformed(evt);
            }
        });
        getContentPane().add(btnPrimeiro, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 560, -1, -1));

        btnAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (2).png"))); // NOI18N
        btnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorActionPerformed(evt);
            }
        });
        getContentPane().add(btnAnterior, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 560, -1, -1));

        btnUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (16).png"))); // NOI18N
        btnUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUltimoActionPerformed(evt);
            }
        });
        getContentPane().add(btnUltimo, new org.netbeans.lib.awtextra.AbsoluteConstraints(840, 560, -1, -1));

        jSeparator1.setForeground(new java.awt.Color(0, 102, 102));
        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 312, 500, -1));

        jSeparator2.setForeground(new java.awt.Color(0, 102, 102));
        getContentPane().add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 160, 490, -1));

        setSize(new java.awt.Dimension(1055, 661));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void textEmail2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textEmail2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textEmail2ActionPerformed

    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
        NovoFornecedor();
    }//GEN-LAST:event_btnNovoActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        Cancelar();
        conexao.desconecta();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        conexao.conexao();
        String sqlInserir = ("INSERT INTO cadastrofabricante (cnpj_fabricante, cpf_fabricante, nome_fabricante, endereco_fabricante, bairro_fabricante, cidade_fabricante, uf_fabricante, cep_fabricante, telefone_fabricante, celular_fabricante, tel_comercial_fabricante, email1_fabricante, email2_fabricante, observacoes_fabricante) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        try {
            PreparedStatement pst = conexao.con.prepareStatement(sqlInserir);
            pst.setString(1, FormattedTextCNPJ.getText());
            pst.setString(2, formattedTextCPF.getText());
            pst.setString(3, textNome.getText());
            pst.setString(4, textEndereco.getText());
            pst.setString(5, textBairro.getText());
            pst.setString(6, textCidade.getText());
            pst.setString(7, (String) boxUF.getSelectedItem());
            pst.setString(8, formattedTextCep.getText());
            pst.setString(9, formattedTextTel.getText());
            pst.setString(10, formattedTextCel.getText());
            pst.setString(10, formattedTextCom.getText());
            pst.setString(11, textEmail1.getText());
            pst.setString(11, textEmail2.getText());
            pst.setString(12, textAreaObs.getText());
            pst.execute();
            pst.close();
            JOptionPane.showMessageDialog(null, "Salvo com Sucesso!");
            geraTabela("select * from cadastrofabricante order by idfabricante");
            //conexao.desconecta();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Falha ao inserir fornecedor" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        conexao.conexao();
        String sqlAlterar = (" update cadastrofabricante set (cnpj_fabricante, cpf_fabricante, nome_fabricante, endereco_fabricante, bairro_fabricante, cidade_fabricante, uf_fabricante, cep_fabricante, telefone_fabricante, celular_fabricante, tel_comercial_fabricante, email1_fabricante, email2_fabricante, observacoes_fabricante) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?) where idfabricante = ?");
        try {
            PreparedStatement pst = conexao.con.prepareStatement(sqlAlterar);
            pst.setString(1, FormattedTextCNPJ.getText());
            pst.setString(2, formattedTextCPF.getText());
            pst.setString(3, textNome.getText());
            pst.setString(4, textEndereco.getText());
            pst.setString(5, textBairro.getText());
            pst.setString(6, textCidade.getText());
            pst.setString(7, (String) boxUF.getSelectedItem());
            pst.setString(8, formattedTextCep.getText());
            pst.setString(9, formattedTextTel.getText());
            pst.setString(10, formattedTextCel.getText());
            pst.setString(11, formattedTextCom.getText());
            pst.setString(12, textEmail1.getText());
            pst.setString(13, textEmail2.getText());
            pst.setString(14, textAreaObs.getText());
            pst.executeUpdate();
            pst.close();
            JOptionPane.showMessageDialog(null, "Alterado com Sucesso!");
            geraTabela("select * from cadastrofabricante order by idfabricante");
            //conexao.desconecta();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Falha ao Alterar fornecedor" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnAlterarActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        conexao.conexao();
        String sqlExcluir = (" delete from cadastrofabricante where idfabricante ='" + this.textIdFabricante.getText() + "'");
        try {
            conexao.executaSQL(sqlExcluir);
            conexao.pst.close();
            JOptionPane.showMessageDialog(null, "Excluido com Sucesso!");
            geraTabela("select * from cadastrofabricante order by idfabricante");
            //conexao.desconecta();
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Erro ao excluir" + erro);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProximoActionPerformed
        conexao.conexao();
        try {
            conexao.rs.next();
            textIdFabricante.setText(String.valueOf(conexao.rs.getInt("codigo_funcionario")));
            FormattedTextCNPJ.setText(conexao.rs.getString("cnpj_fabricante"));
            formattedTextCPF.setText(conexao.rs.getString("cpf_fabricante"));
            textNome.setText(conexao.rs.getString("nome_fabricante"));
            textEndereco.setText(conexao.rs.getString("endereco_fabricante"));
            textBairro.setText(conexao.rs.getString("bairro_fabricante"));
            textCidade.setText(conexao.rs.getString("cidade_fabricante"));
            formattedTextCep.setText(conexao.rs.getString("cep_fabricante"));
            formattedTextTel.setText(conexao.rs.getString("telefone_fabricante"));
            formattedTextCel.setText(conexao.rs.getString("celular_fabricante"));
            formattedTextCom.setText(conexao.rs.getString("tel_comercial_fabricante"));
            textEmail1.setText(conexao.rs.getString("email1_fabricante"));
            textEmail2.setText(conexao.rs.getString("email2_fabricante"));
            textAreaObs.setText(conexao.rs.getString("observacoes_fabricante"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,"Erro Proximo cfa"+ ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnProximoActionPerformed

    private void btnPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrimeiroActionPerformed
        NovoFornecedor();
        conexao.conexao();
        try {
            conexao.executaSQL("select * from cadastrofabricante");
            conexao.rs.first();
            textIdFabricante.setText(String.valueOf(conexao.rs.getInt("codigo_funcionario")));
            FormattedTextCNPJ.setText(conexao.rs.getString("cnpj_fabricante"));
            formattedTextCPF.setText(conexao.rs.getString("cpf_fabricante"));
            textNome.setText(conexao.rs.getString("nome_fabricante"));
            textEndereco.setText(conexao.rs.getString("endereco_fabricante"));
            textBairro.setText(conexao.rs.getString("bairro_fabricante"));
            textCidade.setText(conexao.rs.getString("cidade_fabricante"));
            formattedTextCep.setText(conexao.rs.getString("cep_fabricante"));
            formattedTextTel.setText(conexao.rs.getString("telefone_fabricante"));
            formattedTextCel.setText(conexao.rs.getString("celular_fabricante"));
            formattedTextCom.setText(conexao.rs.getString("tel_comercial_fabricante"));
            textEmail1.setText(conexao.rs.getString("email1_fabricante"));
            textEmail2.setText(conexao.rs.getString("email2_fabricante"));
            textAreaObs.setText(conexao.rs.getString("observacoes_fabricante"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,"Erro botão first cfa " +ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnPrimeiroActionPerformed

    private void btnAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnteriorActionPerformed
        conexao.conexao();
        try {
            conexao.rs.previous();
            textIdFabricante.setText(String.valueOf(conexao.rs.getInt("codigo_funcionario")));
            FormattedTextCNPJ.setText(conexao.rs.getString("cnpj_fabricante"));
            formattedTextCPF.setText(conexao.rs.getString("cpf_fabricante"));
            textNome.setText(conexao.rs.getString("nome_fabricante"));
            textEndereco.setText(conexao.rs.getString("endereco_fabricante"));
            textBairro.setText(conexao.rs.getString("bairro_fabricante"));
            textCidade.setText(conexao.rs.getString("cidade_fabricante"));
            formattedTextCep.setText(conexao.rs.getString("cep_fabricante"));
            formattedTextTel.setText(conexao.rs.getString("telefone_fabricante"));
            formattedTextCel.setText(conexao.rs.getString("celular_fabricante"));
            formattedTextCom.setText(conexao.rs.getString("tel_comercial_fabricante"));
            textEmail1.setText(conexao.rs.getString("email1_fabricante"));
            textEmail2.setText(conexao.rs.getString("email2_fabricante"));
            textAreaObs.setText(conexao.rs.getString("observacoes_fabricante"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,"Erro previous cfa"+ ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnAnteriorActionPerformed

    private void btnUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUltimoActionPerformed
        NovoFornecedor();
        conexao.conexao();
        try {
            conexao.executaSQL("select * from cadastrofabricante");
            conexao.rs.last();
            textIdFabricante.setText(String.valueOf(conexao.rs.getInt("idfabricante")));
            FormattedTextCNPJ.setText(conexao.rs.getString("cnpj_fabricante"));
            formattedTextCPF.setText(conexao.rs.getString("cpf_fabricante"));
            textNome.setText(conexao.rs.getString("nome_fabricante"));
            textEndereco.setText(conexao.rs.getString("endereco_fabricante"));
            textBairro.setText(conexao.rs.getString("bairro_fabricante"));
            textCidade.setText(conexao.rs.getString("cidade_fabricante"));
            formattedTextCep.setText(conexao.rs.getString("cep_fabricante"));
            formattedTextTel.setText(conexao.rs.getString("telefone_fabricante"));
            formattedTextCel.setText(conexao.rs.getString("celular_fabricante"));
            formattedTextCom.setText(conexao.rs.getString("tel_comercial_fabricante"));
            textEmail1.setText(conexao.rs.getString("email1_fabricante"));
            textEmail2.setText(conexao.rs.getString("email2_fabricante"));
            textAreaObs.setText(conexao.rs.getString("observacoes_fabricante"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,"Erro last cfa" +ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnUltimoActionPerformed

    public void NovoFornecedor() {
        FormattedTextCNPJ.setEnabled(true);
        formattedTextCPF.setEnabled(true);
        formattedTextCel.setEnabled(true);
        formattedTextCep.setEnabled(true);
        formattedTextCom.setEnabled(true);
        formattedTextTel.setEnabled(true);
        boxUF.setEnabled(true);
        textAreaObs.setEnabled(true);
        textAreaObs.setEnabled(true);
        textCidade.setEnabled(true);
        textEmail1.setEnabled(true);
        textEmail2.setEnabled(true);
        textEndereco.setEnabled(true);
        textNome.setEnabled(true);
        textNome.requestFocus();
    }

    public void Cancelar() {
        FormattedTextCNPJ.setText("");
        formattedTextCPF.setText("");
        formattedTextCel.setText("");
        formattedTextCep.setText("");
        formattedTextCom.setText("");
        formattedTextTel.setText("");
        textAreaObs.setText("");
        textAreaObs.setText("");
        textCidade.setText("");
        textEmail1.setText("");
        textEmail2.setText("");
        textEndereco.setText("");
        textNome.setText("");
        FormattedTextCNPJ.setEnabled(false);
        formattedTextCPF.setEnabled(false);
        formattedTextCel.setEnabled(false);
        formattedTextCep.setEnabled(false);
        formattedTextCom.setEnabled(false);
        formattedTextTel.setEnabled(false);
        boxUF.setEnabled(false);
        textAreaObs.setEnabled(false);
        textAreaObs.setEnabled(false);
        textCidade.setEnabled(false);
        textEmail1.setEnabled(false);
        textEmail2.setEnabled(false);
        textEndereco.setEnabled(false);
        textNome.setEnabled(false);
        btnNovo.requestFocus();
    }

    public void geraTabela(String SQL) {
        ArrayList dados = new ArrayList();
        String[] Colunas = new String[]{"Codigo", "Nome", "Telefone","telefone Comercial","E-mail","E-mail"};
        conexao.executaSQL(SQL);
        try {
            conexao.rs.first();
            do {
                dados.add((new Object[]{conexao.rs.getInt("idfabricante"),conexao.rs.getString("nome_fabricante"),conexao.rs.getString("tel_comercial_fabricante"),conexao.rs.getString("email1_fabricante"),conexao.rs.getString("email2_fabricante")}));
            } while (conexao.rs.next());
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro ao preencher o arrayList" + ex);
            conexao.desconecta();
        }
        ModeloTabela modeloTabela = new ModeloTabela(dados, Colunas);
        tableFabricante.setModel(modeloTabela);
        tableFabricante.getColumnModel().getColumn(0).setPreferredWidth(60);
        tableFabricante.getColumnModel().getColumn(0).setResizable(false);
        tableFabricante.getColumnModel().getColumn(1).setPreferredWidth(190);
        tableFabricante.getColumnModel().getColumn(1).setResizable(false);
        tableFabricante.getColumnModel().getColumn(2).setPreferredWidth(80);
        tableFabricante.getColumnModel().getColumn(2).setResizable(false);
        tableFabricante.getColumnModel().getColumn(2).setPreferredWidth(80);
        tableFabricante.getColumnModel().getColumn(2).setResizable(false);
        tableFabricante.getColumnModel().getColumn(2).setPreferredWidth(280);
        tableFabricante.getColumnModel().getColumn(2).setResizable(false);
        tableFabricante.getColumnModel().getColumn(2).setPreferredWidth(280);
        tableFabricante.getColumnModel().getColumn(2).setResizable(false);

        tableFabricante.getTableHeader().setReorderingAllowed(false);
        tableFabricante.setAutoResizeMode(tableFabricante.AUTO_RESIZE_OFF);
        tableFabricante.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField FormattedTextCNPJ;
    private java.util.List<br.com.model.Acessarsistema> acessarsistemaList;
    private javax.persistence.Query acessarsistemaQuery;
    private javax.swing.JComboBox boxUF;
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnPrimeiro;
    private javax.swing.JButton btnProximo;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JButton btnUltimo;
    private java.util.List<br.com.model.Cadastrofabricante> cadastrofabricanteList;
    private javax.persistence.Query cadastrofabricanteQuery;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JFormattedTextField formattedTextCPF;
    private javax.swing.JFormattedTextField formattedTextCel;
    private javax.swing.JFormattedTextField formattedTextCep;
    private javax.swing.JFormattedTextField formattedTextCom;
    private javax.swing.JFormattedTextField formattedTextTel;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lblBairro;
    private javax.swing.JLabel lblCadastroFornecedor;
    private javax.swing.JLabel lblCelular;
    private javax.swing.JLabel lblCep;
    private javax.swing.JLabel lblCidade;
    private javax.swing.JLabel lblCnpj;
    private javax.swing.JLabel lblCpf;
    private javax.swing.JLabel lblEmail1;
    private javax.swing.JLabel lblEmail2;
    private javax.swing.JLabel lblEndereco;
    private javax.swing.JLabel lblIdFabricante;
    private javax.swing.JLabel lblNome;
    private javax.swing.JLabel lblTelComercial;
    private javax.swing.JLabel lblTelefone;
    private javax.swing.JLabel lblUf;
    private javax.swing.JTable tableFabricante;
    private javax.swing.JTextArea textAreaObs;
    private javax.swing.JTextField textBairro;
    private javax.swing.JTextField textCidade;
    private javax.swing.JTextField textEmail1;
    private javax.swing.JTextField textEmail2;
    private javax.swing.JTextField textEndereco;
    private javax.swing.JTextField textIdFabricante;
    private javax.swing.JTextField textNome;
    // End of variables declaration//GEN-END:variables
}
